$d = (function(){

    var version = '0.0.1';

    var areaName = 'debugArea';

    var init = function() {
        $("<div/>").attr("id", areaName)
            .css({
                backgroundColor: '#333',
                padding: '2px',
                fontSize: '0.8em',
                color: 'red'})
            .prependTo(document.body);
    };

    var print = function(text) {
        if (!document.getElementById(areaName)) {
            init();
        }
        if (text == '') {
            return;
        }

        var appendDom = $(document.createElement('div'))
            .css({backgroundColor: '#EEE', paddingLeft: '5px'})
            .html(text)
            .appendTo("#" + areaName);
        $("#" + areaName + "> div:odd")
            .css({backgroundColor: '#DDD'});
    };


    return {
        p: function(target) {
            var type = typeof(target);
            if (type == 'object') {
                result = [];
                for(var i in target) {
                    result.push("[" + i + "]" + "&nbsp;=&nbsp;" + target[i]);
                }
                target = "<br/>" + result.join("<br/>");
            }
            print(type + "&nbsp;=>&nbsp;" + target);
        },

//        methods: function(obj) {
//            var result = [];
//            for (var i in obj) {
//                if (typeof(obj[i]) == "function") {
//                    result.push(i);
//                }
//            }
//            if (result.length == 0) {
//                result.push('No methods.');
//            }
//            print(result.join(', '));
//        },
//
//        props: function(obj) {
//            var result = [];
//            for (var i in obj) {
//                if (typeof(obj[i]) != "function") {
//                    result.push(i);
//                }
//            }
//            if (result.length == 0) {
//                result.push('No properties.');
//            }
//            print(result.join(", "));
//        },        

        // benchmark
        bm: function(id, func) {
            var start = new Date();
            func();
            var end = new Date();
            var elapsed = end.getTime() - start.getTime();
            print(id + ": " + elapsed + "(ms)");
        },

        jquery_dump: function(obj) {
            var htmls = [];
            for(var i = 0; i < obj.length; i++) {
                var html = '[' + i + ']: ';
                if($.browser.msie) {
                    html += obj[i].outerHTML.replace(/^[\r\n\t]+/, '');
                } else {
                    html += '&lt;' + obj[i].nodeName.toLowerCase() + '&gt;';
                    html += obj[i].innerHTML;
                    html += '&lt;\/' + obj[i].nodeName.toLowerCase() + '&gt;';
                }
                htmls.push(html);
            }
            print(htmls.join('<br />'));
        }
    }
})();
